package com.edu.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class MyDataSource implements BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean {
    private String username;
    private String password;
    private String url;
    private String driver;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        System.out.println("2 执行了用户的setter方法");
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public MyDataSource() {
        System.out.println("1 执行了MyDataSource无参构造方法");
    }

    public void getConnection() {
        System.out.println("执行了Connection业务方法");
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("3 执行了 beanNameAware接口的方法");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("9 执行了DisposableBean接口的销毁方法");
    }

    public void myDestroy() {
        System.out.println("10 执行了自定义的销毁方法");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("6 执行了 InitializingBean 接口的初始化方法");
    }

    public void myInit() {
        System.out.println("7执行了自定义的初始化方法");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("4 执行了 ApplicationContextAware接口的方法");
    }
}
